// Variables
// (c) jimon game studio

#ifndef JEH_IVARIABLES
#define JEH_IVARIABLES

#include "Config_Engine.h"
#include "jeUnknown.h"
#include "jeSingleton.h"
#include "jeVariable.h"
#include "jeMemory.h"


namespace je
{
	namespace core
	{
		//! Variables
		class IVariables:public je::jeUnknown
		{
		public:
			//! Destructor
			virtual ~IVariables()
			{
			}

			//! Set Variable
			virtual void SetVariable(const jeStringc & Name,SystemVariableType Type,void * Data) = 0;

			//! Get Variable
			virtual jeVariable * GetVariable(const jeStringc & Name) = 0;

			//! Set Variable float 32
			virtual void SetVariable(const jeStringc & Name,f32 Value)
			{
				f32 * Data;
				JENEW(Data,f32)
				(*Data) = Value;
				SetVariable(Name,SVT_FLOAT32,Data);
			}

			//! Set Variable int 32
			virtual void SetVariable(const jeStringc & Name,s32 Value)
			{
				s32 * Data;
				JENEW(Data,s32)
				(*Data) = Value;
				SetVariable(Name,SVT_INT32,Data);
			}

			//! Set Variable c8
			virtual void SetVariable(const jeStringc & Name,c8 Value)
			{
				c8 * Data;
				JENEW(Data,c8)
				(*Data) = Value;
				SetVariable(Name,SVT_BYTE,Data);
			}

			//! Set Variable string
			virtual void SetVariable(const jeStringc & Name,jeStringd Value)
			{
				jeStringd * Data;
				JENEW(Data,jeStringd)
				(*Data) = Value;
				SetVariable(Name,SVT_STRING,Data);
			}

			//! Get Variable f32
			virtual f32 GetVariablef32(const jeStringc & Name)
			{
				jeVariable * Variable = GetVariable(Name);
				if(Variable)
					return *static_cast<f32*>(Variable->Data);
				else
					return 0.0f;
			}

			//! Get Variable s32
			virtual s32 GetVariables32(const jeStringc & Name)
			{
				jeVariable * Variable = GetVariable(Name);
				if(Variable)
					return *static_cast<s32*>(Variable->Data);
				else
					return 0;
			}

			//! Get Variable c8
			virtual c8 GetVariablec8(const jeStringc & Name)
			{
				jeVariable * Variable = GetVariable(Name);
				if(Variable)
					return *static_cast<c8*>(Variable->Data);
				else
					return 0;
			}

			//! Get Variable string
			virtual jeStringd GetVariableString(const jeStringc & Name)
			{
				jeVariable * Variable = GetVariable(Name);
				if(Variable)
				{
					return *static_cast<jeStringd*>(Variable->Data);
				}
				else
					return jeStringd("");
			}
		};

		DECLARE_SINGLETON_E(JE_ENGINE_FUNCTION_API,JE_ENGINE_FUNCTION_CALL,Variables)
	}
}

#define JESETVARIABLE(__var,__val) je::core::GetVariables()->SetVariable(__var,__val);

#endif
